/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : Jul 7, 2012  11:42:49 AM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : apps.business.process.construction.contract
 * File Name : ContractContractorThread.java
 * TODO
 */
package apps.business.process.construction.contract;

import java.util.ArrayList;
import java.util.List;

import jpa.entitys.promis.common.CostProject;

import org.apache.log4j.Logger;
import promis.utility.CommonService;
import apps.promis.in.common.ProjectAction;
import apps.promis.out.construction.VwSyncPoContractorAction;

/**
 * @author chatree
 *
 */
public class ContractContractorThread extends Thread {
	
	private static final Logger log = Logger.getLogger(ContractContractorThread.class);
	private String company = null;
    private String project = null;
	public ContractContractorThread(String company, String project){
		this.company = company;
		this.project = project;
	}
	
	public void run()
    {
		List<CostProject> lst = null;
		try {
			lst = new ProjectAction().findAll();
			log.info("CostProject Size:"+ CommonService.getSize(lst));		
			System.out.println("CostProject Size:"+ CommonService.getSize(lst));
			System.out.print("Please any key : "); System.in.read();
		} catch (Exception e1) {
			log.error(e1.getMessage());
			System.err.println(e1.getMessage());
		}
		
		for(CostProject project : lst){
			try {	    			
	        	List<Object[]> lst1 = new VwSyncPoContractorAction().findAllByProject(project.getId().getCompany(), project.getId().getProject(), null, null);
	        	
	        	if(lst != null){
	        		for(Object[] value : lst1){
	        			
	        			setName(company + project +CommonService.IsNullRString(value[3]) + CommonService.IsNullRString(value[4]));
	        			
	        			new ContractContractorLowRiseProcessing().ProcessingContarct(project.getId().getCompany(), project.getId().getProject(), CommonService.IsNullRString(value[2]), CommonService.IsNullRString(value[3]), CommonService.IsNullRString(value[4]));
	        			//sleep(1000);
	        		}
	        	}
			} catch (Exception e) {
				log.error(e.getMessage());
				System.err.println(e.getMessage());
			}
		}
    }
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try{
			
			new ContractContractorThread("cc", "xx").start();	
			
		}catch(Exception e){
			log.error(e.getMessage());
			System.err.println(e.getMessage());
		}
	}
}
